import store  from "@/store/index.js"

const BASE_URL = store.state.baseUrl;

export function request(config={}){	
	let {
		url,
		data={},
		method="GET",
		header={}
	} = config
	console.log(BASE_URL)
	url = BASE_URL+url
	// url='http://127.0.0.1:5001/store/raw/sample/yp/data?page=1&limit=10'
	header['access-key'] = "xxm123321@#"
	
	
	return new Promise((resolve,reject)=>{		
		uni.request({
			url,
			data,
			method,
			header,
			success:res=>{
				// console.log(res)
				if(res.data.code===0 || res.data.code==='0' ){
					resolve(res.data)
				}else if(res.data.code === 400 || res.data.code === '400' ){
					uni.showModal({
						title:"错误提示",
						content:res.data.msg,
						showCancel:false
					})
					reject(res.data)
				}else{
					uni.showToast({
						title:res.data.msg,
						icon:"none"
					})
					reject(res.data)
				}				
			},
			fail:err=>{
				reject(err)
			}
		})
	})
}

export function requestConnectPrintTool(config={}){	
	let {
		url,
		data={},
		method="GET",
		header={}
	} = config
	
	
	url='http://127.0.0.1:5003/connect'
	
	
	
	return new Promise((resolve,reject)=>{		
		uni.request({
			url,
			data,
			method,
			header,
			success:res=>{				
				
				resolve(res.data)
				
			},
			fail:err=>{
				reject(err)
			}
		})
	})
}
